Transforming while/do/for/foreach-Loops into Recursive Methods
نویسندگان
چکیده
In software engineering, taking a good election between recursion and iteration is essential because their efficiency and maintenance are different. In fact, developers often need to transform iteration into recursion (e.g., in debugging, to decompose the call graph into iterations); thus, it is quite surprising that there does not exist a public transformation from loops to recursion that handles all kinds of loops. This article describes a transformation able to transform iterative loops into equivalent recursive methods. The transformation is described for the programming language Java, but it is general enough as to be adapted to many other languages that allow iteration and recursion. We describe the changes needed to transform loops of types while/do/for/foreach into recursion. Each kind of loop requires a particular treatment that is described and exemplified.
منابع مشابه
Automatic transformation of iterative loops into recursive methods
Context: In software engineering, taking a good election between recursion and iteration is essential because their efficiency and maintenance are different. In fact, developers often need to transform iteration into recursion (e.g., in debugging, to decompose the call graph into iterations); thus, it is quite surprising that there does not exist a public transformation from loops to recursion ...
متن کاملProving program refinements and transformations
In this thesis we develop a theory of program refinement and equivalence which can be used to develop practical tools for program development, analysis and modification. The theory is based on the use of general specifications and an imperative kernel language. We use weakest preconditions, expressed as formulae in infinitary logic to prove refinement and equivalence between programs. The kerne...
متن کاملNumerical solution of higher index DAEs using their IAE's structure: Trajectory-prescribed path control problem and simple pendulum
In this paper, we solve higher index differential algebraic equations (DAEs) by transforming them into integral algebraic equations (IAEs). We apply collocation methods on continuous piece-wise polynomials space to solve the obtained higher index IAEs. The efficiency of the given method is improved by using a recursive formula for computing the integral part. Finally, we apply the obtained algo...
متن کاملData Retrieval and Aggregates in SQL*/NR
Standard SQL is incapable of handling recursive database queries and nested relations. A proposed solution to allow recursion in SQL was given in SQL KC93], while a solution to allow nested relations in SQL was given in SQL=NF RKB87]. However, these two problems with SQL were handled separately, and an extended SQL that handles both recursive queries and nested relations is still lacking. To ov...
متن کاملA Purely Logical Approach to Program Termination
We present our work in progress concerning the logical foundations of the analysis of termination for imperative recursive programs. The analysis is based on forward symbolic execution [12] and functional semantics. The distinctive feature of our approach is the formulation of the termination condition as an induction principle developed from the structure of the program with respect to iterati...
متن کاملذخیره در منابع من
با ذخیره ی این منبع در منابع من، دسترسی به آن را برای استفاده های بعدی آسان تر کنید
عنوان ژورنال:
- CoRR
دوره abs/1410.4956 شماره
صفحات -
تاریخ انتشار 2014